import VuexPersist from "vuex-persist";
import { createStore } from "vuex";
import getters from "./getters";
import user from "./modules/user";
import approval from "./modules/approval";
import defaultSetting from "../common/utils/defaultSetting";

// 创建对象，借助浏览器缓存，存入localStorage
const vuexLocal = new VuexPersist({
  // 存储键名
  key: `${defaultSetting.from}_${defaultSetting.name}_vuex`,
  // 存储方式
  storage: window.localStorage,
  reducer(vuexStore) {
    return {
      // 持久化存储的数据
      app: vuexStore.app,
    };
  },
});
// 引入该插件
export default createStore({
  modules: {
    user,
    approval,
  },
  getters,
  state: {},
  mutations: {},
  plugins: [vuexLocal.plugin],
});
